class StudentManger():
    def __init__(self):
        self.students = []

    def run(self):
        while True:
            self.show_menu()
            number = int(input('请输入对应功能的序号:'))
            if number == 1:
                self.add_student()
            elif number == 2:
                self.del_student()
            elif number == 3:
                self.update_student()



    def show_menu(self):
        print("""
               ************************
               *    1 添加学生        *
               *    2 删除学生        *
               *    3 修改学生        *
               *    4 查询学生        *
               *    5 查询所有学生    *
               *    6 保存信息        *
               *    7 推出系统        *
               ************************ """)

    def add_student(self):
        """添加学生"""
        print('请选择添加的信息:')
        name = input('姓名:')
        code = input('学号:')
        age = input('年龄:')
        student = self.pd(code)
        if student:
            print('该学生已存在')
        else:
            student = Student(name, age, code)
            self.students.append(student)
            print(f'{name}学生已添加')

    def del_student(self):
        """删除学生"""
        code = input('请输入学生学号：')
        student = self.pd(code)
        if student:
                self.students.remove(student)
                print(f'学号为{code}的学生删除成功')
        else:
            print('该学生不存在')

    def pd(self, input_code):
        """根据学号判断是否存在"""
        for i in range(len(self.students)):
            if input_code == self.students[i].code:
                return self.students[i]
        return False

    def update_student(self):
        '''修改学生信息'''
        code=input('请输入学生学号：')
        student=self.pd(code)
        if student:
            name = input("请输入学生姓名")
            age = input("请输入年龄")
            student.name = name
            student.age = age
            for i in self.students:
                print(i.code, i.name, i.age)
        else:
            print('该学生不存在')




class Student():
    def __init__(self, n, a, c):
        self.name = n
        self.age = a
        self.code = c


# print("""********************
# *    1 添加学生    *
#
# """)

s_manager = StudentManger()
s_manager.run()